﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace _1.VersionAttribute
{
    class VersionInAction
    {
        static void Main(string[] args)
        {
            ExtractMethodVersion();
        }

        [Version("1.2.3.4", OptionalText = "OptionalText")]
        public static void MethodUsingCustomAttributes()
        {

        }

        [Version("1.3.4.5", OptionalText = "Some text")]
        private static void ExtractMethodVersion()
        {
            Type type = typeof(VersionInAction);
            var methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly
                | BindingFlags.Instance | BindingFlags.Static);
                //.Where(x => x.IsPrivate).
                // SelectMany(x => x.GetCustomAttributes(typeof(VersionAttribute), false));

            foreach (MemberInfo method in methods)
            {
                if (method.Name == "ExtractMethodVersion")
                {
                    Object[] customAttributes = method.GetCustomAttributes(false);
                    VersionAttribute versionAttribute = (VersionAttribute)customAttributes[0];
                    Console.WriteLine(versionAttribute.VersionName + " " + versionAttribute.OptionalText);
                }
            }
        }
    }
}
